package stu.cn.ua.rgr;

import javax.swing.SwingUtilities;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Rectangle;
import javax.swing.JTabbedPane;
import java.awt.Color;

import javax.swing.ButtonGroup;
import javax.swing.JTextField;
import javax.swing.JButton; 
import javax.swing.JTextArea;
import javax.swing.JRadioButton;
import javax.swing.BorderFactory;
import javax.swing.border.BevelBorder;
import java.awt.SystemColor;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import java.awt.GridBagConstraints;
import javax.swing.JSplitPane;


import stu.cn.ua.rgr.FactoryForRgrModel;
import process.Dispatcher;
import widgets.ChooseData;
import widgets.ChooseRandom;
import rnd.Erlang;
import widgets.Diagram;
import stat.DiscretHisto;
import widgets.experiments.ExperimentControl;
import widgets.regres.*;
import transProcess.TransMonitorView;
import stu.cn.ua.rgr.Main;




/**
 * @author Juls
 *
 */

public class Main {

	private JFrame jFrame = null;  //  @jve:decl-index=0:visual-constraint="11,11"
	private JPanel jContentPane = null;
	private JPanel jPanel1 = null;
	private JTabbedPane jTabbedPane1 = null;
	private JPanel jPanel2 = null;
	private JPanel jPanel3 = null;
	private JLabel jLabel = null;
	private JPanel jPanel = null;
	private JPanel jPanel4 = null;
	private JPanel jPanel5 = null;
	private JPanel jPanel6 = null;
	private JPanel jPanel7 = null;
	private JPanel jPanel8 = null;
	private JPanel jPanel9 = null;
	private JTextField jTextCntSiv = null;
	private JTextField jTextCntGr = null;
	private JTextField jTextTime = null;
	private JSplitPane jSplitPane = null;
	private JButton jButtonStat = null;
	private ChooseRandom chooseRandomGrMove = null;
	private ChooseRandom chooseRandomSivTime = null;
	private ChooseRandom chooseRandomGrUpload = null;
	private ChooseRandom chooseRandomGrDownload = null;
	private Diagram diagramSiv = null;
	private Diagram diagramGrUpload = null;
	private Diagram diagramGrDownload = null;
	private JButton jButtonStart = null;
	//private DiscretHisto histo = null;  //  @jve:decl-index=0:visual-constraint="800,471"
	private JTextArea jTextArea = null;
	private Diagram diagram3 = null;
	private Diagram diagram31 = null;
	private JTextArea jTextArea1 = null;
	//private DiscretHisto histo1 = null;  //  @jve:decl-index=0:visual-constraint="857,477"
	private JPanel jPanel10 = null;  //  @jve:decl-index=0:visual-constraint="824,138"
	private Diagram diagramZavisimost = null;
	private JPanel jPanelZav = null;
	private JRadioButton jRadioBChergaAvt = null;
	private JRadioButton jRadioBVremProstoya = null;
	private ExperimentControl experimentControl = null;
	private RegresAnaliser regresAnaliser = null;
	private FactoryForRgrModel factoryForRgrModel1 = null;
	private ChooseData chooseDataGruz = null;  //  @jve:decl-index=0:visual-constraint="546,593"
	private JPanel jPanel111 = null;  //  @jve:decl-index=0:visual-constraint="809,97"
	private TransMonitorView transMonitorView = null;
	private Main XYZ = null;
	private Diagram diagram4 = null;
	private JRadioButton jRadioButton2 = null;
	private JRadioButton jRadioButton3 = null;
	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	
	private void startTest() {
		getDiagramSiv().clear();
		getDiagramGrUpload().clear();
		getDiagramGrDownload().clear();
		FactoryForRgrModel factory = new FactoryForRgrModel(Main.this);
		final Dispatcher dispatcher = new Dispatcher();
		Model model = factory.createModel(dispatcher);
		model.initForTest();
		dispatcher.start();
		getJButtonStat().setEnabled(false);
		// Створюємо потік, що чекає завершення роботи диспетчера,
		// а після цього відновлює доступність кнопки "Старт"
		new Thread() {
			public void run() {
				// Затримка до кінця моделювання
				try {
					dispatcher.getThread().join();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				getJButtonStat().setEnabled(true);
			}
		}.start();
	}
	
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jPanel1 = new JPanel();
			jPanel1.setLayout(null);
			jPanel1.setBounds(new Rectangle(5, 46, 257, 491));
			jPanel1.setBackground(Color.lightGray);
			jPanel1.setBorder(BorderFactory.createTitledBorder(null, "Параметри системи", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
			jPanel1.setName("");
			jPanel1.add(getJPanel(), null);
			jPanel1.add(getJPanel4(), null);
			jPanel1.add(getJPanel5(), null);
			jPanel1.add(getJPanel6(), null);
			jPanel1.add(getJPanel7(), null);
			jPanel1.add(getJPanel8(), null);
			jPanel1.add(getJPanel9(), null);
		}
		return jPanel1;
	}

	/**
	 * This method initializes jTabbedPane1	
	 * 	
	 * @return javax.swing.JTabbedPane	
	 */
	private JTabbedPane getJTabbedPane1() {
		if (jTabbedPane1 == null) {
			jTabbedPane1 = new JTabbedPane();
			jTabbedPane1.setBounds(new Rectangle(274, 43, 489, 495));
			jTabbedPane1.setBackground(Color.lightGray);
			jTabbedPane1.addTab("Тест моделі", null, getJPanel2(), null);
			jTabbedPane1.addTab("Статистика", null, getJPanel3(), null);
			jTabbedPane1.addTab("Регресивний аналіз", null, getJPanel10(), null);
			jTabbedPane1.addTab("Перехідний процес", null, getJPanel111(), null);
			
			
		}
		return jTabbedPane1;
	}

	/**
	 * This method initializes jPanel2	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel2() {
		if (jPanel2 == null) {
			jPanel2 = new JPanel();
			jPanel2.setLayout(null);
			jPanel2.setBackground(SystemColor.controlHighlight);
			jPanel2.add(getDiagramSiv(), null);
			jPanel2.add(getDiagramGrUpload(), null);
			jPanel2.add(getDiagramGrDownload(), null);
			jPanel2.add(getJButtonStart(), null);
//			jPanel2.addComponentListener(new java.awt.event.ComponentAdapter() {
			jPanel2.addComponentListener(new java.awt.event.ComponentAdapter() {
				public void componentShown(java.awt.event.ComponentEvent e) {
					getJTextTime().select(0, 0);
				}
			});
//				public void componentShown(java.awt.event.ComponentEvent e) {
//					jTextCntSiv.select(0, 0);
//					jTextCntGr.select(0, 0);
//					jTextTime.select(0, 0);
//					
//				}
//			});
			
		}
		return jPanel2;
	}

	/**
	 * This method initializes jPanel3	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel3() {
		if (jPanel3 == null) {
			jPanel3 = new JPanel();
			jPanel3.setLayout(null);
			jPanel3.setBackground(SystemColor.controlHighlight);
			jPanel3.add(getJButtonStat(), null);
			jPanel3.add(getJTextArea(), null);
			jPanel3.add(getDiagram3(), null);
			jPanel3.add(getDiagram31(), null);
			jPanel3.add(getJTextArea1(), null);
			jPanel3.add(getJButtonStat(), null);
			jPanel3.add(getJButtonStat(), null);
			jPanel3.add(getJButtonStat(), null);
			jPanel3.add(getJButtonStat(), null);
			
		}
		return jPanel3;
	}

		
	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBounds(new Rectangle(9, 19, 237, 55));
			jPanel.setBorder(BorderFactory.createTitledBorder(null, "Тривалість поїздки вантажівки", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
			jPanel.add(getChooseRandomGrMove(), null);
		}
		return jPanel;
	}

	/**
	 * This method initializes jPanel4	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel4() {
		if (jPanel4 == null) {
			jPanel4 = new JPanel();
			jPanel4.setLayout(null);
			jPanel4.setBounds(new Rectangle(9, 79, 237, 55));
			jPanel4.setBorder(BorderFactory.createTitledBorder(null, "Тривалість засіву", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
			jPanel4.add(getChooseRandomSivTime(), null);
		}
		return jPanel4;
	}

	/**
	 * This method initializes jPanel5	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel5() {
		if (jPanel5 == null) {
			jPanel5 = new JPanel();
			jPanel5.setLayout(null);
			jPanel5.setBounds(new Rectangle(9, 139, 237, 55));
			jPanel5.setBorder(BorderFactory.createTitledBorder(null, "Тривалість завантаження сівалки", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
			jPanel5.add(getChooseRandomGrUpload(), null);
		}
		return jPanel5;
	}

	/**
	 * This method initializes jPanel6	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel6() {
		if (jPanel6 == null) {
			jPanel6 = new JPanel();
			jPanel6.setLayout(null);
			jPanel6.setBounds(new Rectangle(9, 199, 237, 55));
			jPanel6.setBorder(BorderFactory.createTitledBorder(null, "Тривалість завантаження вантажівки", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
			jPanel6.add(getChooseRandomGrDownload(), null);
		}
		return jPanel6;
	}

	/**
	 * This method initializes jPanel7	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel7() {
		if (jPanel7 == null) {
			jPanel7 = new JPanel();
			jPanel7.setLayout(null);
			jPanel7.setBounds(new Rectangle(9, 279, 237, 60));
			jPanel7.setBorder(BorderFactory.createTitledBorder(null, "Кількість сівалок", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION, new Font("Arial Black", Font.PLAIN, 12), new Color(51, 51, 51)));
			jPanel7.add(getJTextCntSiv(), null);
		}
		return jPanel7;
	}

	/**
	 * This method initializes jPanel8	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel8() {
		if (jPanel8 == null) {
			jPanel8 = new JPanel();
			jPanel8.setLayout(null);
			jPanel8.setBounds(new Rectangle(9, 349, 237, 60));
			jPanel8.setBorder(BorderFactory.createTitledBorder(null, "Кількість вантажівок", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION, new Font("Arial Black", Font.PLAIN, 12), new Color(51, 51, 51)));
			jPanel8.add(getJTextCntGr(), null);
		}
		return jPanel8;
	}

	/**
	 * This method initializes jPanel9	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel9() {
		if (jPanel9 == null) {
			jPanel9 = new JPanel();
			jPanel9.setLayout(null);
			jPanel9.setBounds(new Rectangle(9, 419, 237, 60));
			jPanel9.setBorder(BorderFactory.createTitledBorder(null, "Час моделювання", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION, new Font("Arial Black", Font.PLAIN, 12), new Color(51, 51, 51)));
			jPanel9.add(getJTextTime(), null);
		}
		return jPanel9;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	public JTextField getJTextCntSiv() {
		if (jTextCntSiv == null) {
			jTextCntSiv = new JTextField();
			jTextCntSiv.setBounds(new Rectangle(39, 23, 159, 23));
			jTextCntSiv.setText("5");
			jTextCntSiv.setEditable(true);
			jTextCntSiv.setBackground(Color.white);
			jTextCntSiv.setFont(new Font("Dialog", Font.PLAIN, 12));
			
		}
		return jTextCntSiv;
	}

	/**
	 * This method initializes jTextField1	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	public JTextField getJTextCntGr() {
		if (jTextCntGr == null) {
			jTextCntGr = new JTextField();
			jTextCntGr.setBounds(new Rectangle(39, 24, 159, 23));
			jTextCntGr.setText("5");
		}
		return jTextCntGr;
	}

	/**
	 * This method initializes jTextField2	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	public JTextField getJTextTime() {
		if (jTextTime == null) {
			jTextTime = new JTextField();
			jTextTime.setBounds(new Rectangle(39, 23, 159, 23));
			jTextTime.setText("480");
			jTextTime.addCaretListener(new javax.swing.event.CaretListener() {
				public void caretUpdate(javax.swing.event.CaretEvent e) {
					if (getJPanel2().isShowing()) {
						getDiagramSiv().setHorizontalMaxText(getJTextTime().getText());
						getDiagramGrUpload().setHorizontalMaxText(getJTextTime().getText());
						getDiagramGrDownload().setHorizontalMaxText(getJTextTime().getText());
					}
					
					
					
				}
			});
		}
		return jTextTime;
	}

	/**
	 * This method initializes jSplitPane	
	 * 	
	 * @return javax.swing.JSplitPane	
	 */
	private JSplitPane getJSplitPane() {
		if (jSplitPane == null) {
			jSplitPane = new JSplitPane();
			jSplitPane.setBounds(new Rectangle(260, 44, 13, 495));
		}
		return jSplitPane;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonStat() {
		if (jButtonStat == null) {
			jButtonStat = new JButton();
			jButtonStat.setFont(new Font("Dialog", Font.BOLD, 18));
			jButtonStat.setBounds(new Rectangle(2, 431, 473, 31));
			jButtonStat.setText("Почати експеримент");
			
				
			jButtonStat.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					startStat();
				}
			});
		}
		return jButtonStat;
	}

	/**
	 * This method initializes chooseRandom	
	 * 	
	 * @return widgets.ChooseRandom	
	 */
	public ChooseRandom getChooseRandomGrMove() {
		if (chooseRandomGrMove == null) {
			chooseRandomGrMove = new ChooseRandom();
			chooseRandomGrMove.setBounds(new Rectangle(7, 17, 222, 33));
			
		}
		return chooseRandomGrMove;
	}

	/**
	 * This method initializes chooseRandom1	
	 * 	
	 * @return widgets.ChooseRandom	
	 */
	public ChooseRandom getChooseRandomSivTime() {
		if (chooseRandomSivTime == null) {
			chooseRandomSivTime = new ChooseRandom();
			chooseRandomSivTime.setBounds(new Rectangle(7, 17, 222, 33));
			chooseRandomSivTime.setRandom(new Erlang());
			
		}
		return chooseRandomSivTime;
	}

	/**
	 * This method initializes chooseRandom2	
	 * 	
	 * @return widgets.ChooseRandom	
	 */
	public ChooseRandom getChooseRandomGrUpload() {
		if (chooseRandomGrUpload == null) {
			chooseRandomGrUpload = new ChooseRandom();
			chooseRandomGrUpload.setBounds(new Rectangle(7, 17, 222, 33));
		}
		return chooseRandomGrUpload;
	}

	/**
	 * This method initializes chooseRandom3	
	 * 	
	 * @return widgets.ChooseRandom	
	 */
	public ChooseRandom getChooseRandomGrDownload() {
		if (chooseRandomGrDownload == null) {
			chooseRandomGrDownload = new ChooseRandom();
			chooseRandomGrDownload.setBounds(new Rectangle(7, 17, 222, 33));
		}
		return chooseRandomGrDownload;
	}

	/**
	 * This method initializes diagram	
	 * 	
	 * @return widgets.Diagram	
	 */
	public Diagram getDiagramSiv() {
		if (diagramSiv == null) {
			diagramSiv = new Diagram();
			diagramSiv.setBounds(new Rectangle(3, 30, 240, 180));
			diagramSiv.setTitleText("Черга сівалок на завантаження");
			diagramSiv.setPainterColor(Color.red);
		}
		return diagramSiv;
	}

	/**
	 * This method initializes diagram1	
	 * 	
	 * @return widgets.Diagram	
	 */
	public Diagram getDiagramGrUpload() {
		if (diagramGrUpload == null) {
			diagramGrUpload = new Diagram();
			diagramGrUpload.setBounds(new Rectangle(245, 30, 240, 180));
			diagramGrUpload.setTitleText("Черга вантажівок на поле");
			diagramGrUpload.setPainterColor(Color.red);
		}
		return diagramGrUpload;
	}

	/**
	 * This method initializes diagram2	
	 * 	
	 * @return widgets.Diagram	
	 */
	public Diagram getDiagramGrDownload() {
		if (diagramGrDownload == null) {
			diagramGrDownload = new Diagram();
			diagramGrDownload.setBounds(new Rectangle(3, 240, 240, 180));
			diagramGrDownload.setTitleText("Черга вантажівок на загрузку");
			diagramGrDownload.setPainterColor(Color.red);
		}
		return diagramGrDownload;
	}

	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonStart() {
		if (jButtonStart == null) {
			jButtonStart = new JButton();
			jButtonStart.setBounds(new Rectangle(258, 290, 216, 61));
			jButtonStart.setFont(new Font("Dialog", Font.BOLD, 18));
			jButtonStart.setText("Старт");
			jButtonStart.addActionListener(new java.awt.event.ActionListener() {   
				public void actionPerformed(java.awt.event.ActionEvent e) {    
					startTest();
				}
			
			});
		}
		return jButtonStart;
	}

	
	
	

	/**
	 * This method initializes jTextArea	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getJTextArea() {
		if (jTextArea == null) {
			jTextArea = new JTextArea();
			jTextArea.setBounds(new Rectangle(3, 219, 231, 205));
			jTextArea.setBackground(Color.white);
		}
		return jTextArea;
	}

	/**
	 * This method initializes diagram3	
	 * 	
	 * @return widgets.Diagram	
	 */
	public Diagram getDiagram3() {
		if (diagram3 == null) {
			diagram3 = new Diagram();
			diagram3.setBounds(new Rectangle(5, 15, 232, 189));
			diagram3.setPainterColor(Color.red);
			diagram3.setHorizontalMaxText("48");
			diagram3.setTitleText("Черга вантажівок на поле");
		//	diagram3.setVerticalMaxText("1");
		}
		return diagram3;
	}

	/**
	 * This method initializes diagram31	
	 * 	
	 * @return widgets.Diagram	
	 */
	private Diagram getDiagram31() {
		if (diagram31 == null) {
			diagram31 = new Diagram();
			diagram31.setBounds(new Rectangle(245, 15, 232, 188));
			diagram31.setPainterColor(Color.red);
			diagram31.setTitleText("Черга сівалок на завантаження");
		}
		return diagram31;
	}

	/**
	 * This method initializes jTextArea1	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getJTextArea1() {
		if (jTextArea1 == null) {
			jTextArea1 = new JTextArea();
			jTextArea1.setBounds(new Rectangle(247, 220, 229, 204));
			jTextArea1.setBackground(Color.white);
		}
		return jTextArea1;
	}

	/**
	 * This method initializes histo1	
	 * 	
	 * @return stat.DiscretHisto	
	 */


	/**
	 * This method initializes jPanel10	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel10() {
		if (jPanel10 == null) {
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.gridx = 0;
			gridBagConstraints.gridy = 0;
			jPanel10 = new JPanel();
			jPanel10.setLayout(null);
			jPanel10.setSize(new Dimension(76, 61));
			jPanel10.add(getJPanelZav(), null);
			jPanel10.add(getRegresAnaliser(), null);
			jPanel10.add(getExperimentControl(), null);
			
		}
		return jPanel10;
	}

	/**
	 * This method initializes jPanel11	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	

	/**
	 * This method initializes diagramZavisimost	
	 * 	
	 * @return widgets.Diagram	
	 */
	private Diagram getDiagramZavisimost() {
		if (diagramZavisimost == null) {
			diagramZavisimost = new Diagram();
			diagramZavisimost.setVerticalMaxText("20");
			diagramZavisimost.setHorizontalMaxText("20");
			diagramZavisimost.setPainterColor(Color.red);
			diagramZavisimost.setBounds(new Rectangle(4, 56, 464, 172));
			diagramZavisimost.setTitleText("Залежності");
		}
		return diagramZavisimost;
	}

	/**
	 * This method initializes jPanelZav	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelZav() {
		if (jPanelZav == null) {
			jPanelZav = new JPanel();
			jPanelZav.setLayout(null);
			jPanelZav.setBounds(new Rectangle(4, 230, 474, 233));
			jPanelZav.add(getDiagramZavisimost(), null);
			jPanelZav.add(getJRadioBChergaAvt(), null);
			jPanelZav.add(getJRadioBVremProstoya(), null);
		    ButtonGroup group = new ButtonGroup();
		    group.add(getJRadioBChergaAvt());
		    group.add(getJRadioBVremProstoya());
		}
		return jPanelZav;
	}

	/**
	 * This method initializes jRadioBChergaAvt	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	public JRadioButton getJRadioBChergaAvt() {
		if (jRadioBChergaAvt == null) {
			jRadioBChergaAvt = new JRadioButton();
			jRadioBChergaAvt.setBounds(new Rectangle(11, 5, 275, 18));
			jRadioBChergaAvt.setText("Середній розмір черги вантажівок на поле");
			jRadioBChergaAvt.setSelected(true);
			jRadioBChergaAvt.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jRadioBChergaAvt.isSelected()){
						getDiagramZavisimost().clear();
						getDiagramZavisimost().setTitleText("Залежність сер. розміру черги вантажівок на поле від кіл-ті сівалок");
						jRadioBVremProstoya.setSelected(false);
					}
				}
			});
		}
		return jRadioBChergaAvt;
	}

	/**
	 * This method initializes jRadioBVremProstoya	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	public JRadioButton getJRadioBVremProstoya() {
		if (jRadioBVremProstoya == null) {
			jRadioBVremProstoya = new JRadioButton();
			jRadioBVremProstoya.setBounds(new Rectangle(11, 27, 216, 20));
			jRadioBVremProstoya.setText("Час простою сівалок на поле");
		    jRadioBVremProstoya.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jRadioBVremProstoya.isSelected()){
						getDiagramZavisimost().setTitleText("Залежність часу простою сівалок від їх кількості");
						getDiagramZavisimost().clear();
						jRadioBChergaAvt.setSelected(false);
					}
				}
			});
		}
		return jRadioBVremProstoya;
	}

	/**
	 * This method initializes jPanel111	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel111() {
		if (jPanel111 == null) {
			jPanel111 = new JPanel();
			jPanel111.setLayout(null);
			jPanel111.setSize(new Dimension(119, 105));
			jPanel111.add(getTransMonitorView(), null);
			jPanel111.add(getDiagram4(), null);
			jPanel111.add(getJRadioButton2(), null);
			jPanel111.add(getJRadioButton3(), null);
		}
		return jPanel111;
	}

	/**
	 * This method initializes transMonitorView	
	 * 	
	 * @return transProcess.TransMonitorView	
	 */
	private TransMonitorView getTransMonitorView() {
		if (transMonitorView == null) {
			FactoryForRgrModel factoryForRgrModel1 = new stu.cn.ua.rgr.FactoryForRgrModel(getXYZ());
			transMonitorView = new TransMonitorView();
			transMonitorView.setИнтервал_усреднения("20");
			transMonitorView.setКоличество_интервалов("30");
			transMonitorView.setBounds(new Rectangle(41, 1, 398, 209));
			transMonitorView.setFactory(factoryForRgrModel1);
			transMonitorView.setDiagram(getDiagram4());
			transMonitorView.setПараллельно_моделей("50");
		}
		return transMonitorView;
	}

	/**
	 * This method initializes XYZ	
	 * 	
	 * @return pac.Main	
	 */
	private Main getXYZ() {
		if (XYZ == null) {
			XYZ = new Main();
		}
		return XYZ;
	}

	/**
	 * This method initializes diagram4	
	 * 	
	 * @return widgets.Diagram	
	 */
	private Diagram getDiagram4() {
		if (diagram4 == null) {
			diagram4 = new Diagram();
			diagram4.setTitleText("Перехідний процес для зміни черги вантажівок на поле");
			diagram4.setVerticalMaxText("5");
			diagram4.setPainterColor(Color.BLUE);
			diagram4.setGridByX(5);
			diagram4.setBounds(new Rectangle(42, 267, 394, 195));
			diagram4.setHorizontalMaxText("100");
		}
		return diagram4;
	}

	/**
	 * This method initializes jRadioButton2	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	public JRadioButton getJRadioButton2() {
		if (jRadioButton2 == null) {
			jRadioButton2 = new JRadioButton();
			jRadioButton2.setBounds(new Rectangle(43, 211, 394, 26));
			jRadioButton2.setText("Перехідний процес для зміни черги вантажівок на поле");
			jRadioButton2.setSelected(true);
			jRadioButton2.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jRadioButton2.isSelected()){
						getDiagram4().clear();
						getDiagram4().setTitleText("Перехідний процес для зміни черги вантажівок на поле");
						jRadioButton3.setSelected(false);
				}	
				}
			});
		}
		return jRadioButton2;
	}

	/**
	 * This method initializes jRadioButton3	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	public JRadioButton getJRadioButton3() {
		if (jRadioButton3 == null) {
			jRadioButton3 = new JRadioButton();
			jRadioButton3.setBounds(new Rectangle(43, 238, 395, 23));
			jRadioButton3.setText("Перехідний процес часу чекання сівалки");
			jRadioButton3.addItemListener(new java.awt.event.ItemListener() {
				public void itemStateChanged(java.awt.event.ItemEvent e) {
					if (jRadioButton3.isSelected()){
						getDiagram4().setTitleText("Перехідний процес часу чекання сівалки");
						getDiagram4().clear();
						jRadioButton2.setSelected(false);
					}	
				}
			});
		}
		return jRadioButton3;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Main application = new Main();
				application.getJFrame().setVisible(true);
			}
		});
	}

	/**
	 * This method initializes jFrame
	 * 
	 * @return javax.swing.JFrame
	 */
	private JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			jFrame.setSize(784, 576);
			jFrame.setContentPane(getJContentPane());
			jFrame.setTitle("JavaApplicationByKI-091");
		}
		return jFrame;
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(5, 4, 757, 39));
			jLabel.setFont(new Font("Times New Roman", Font.BOLD | Font.ITALIC, 15));
			jLabel.setBackground(Color.cyan);
			jLabel.setText("    Курсовий проект з моделювання \"Сiвалка\". Виконали студенти гр. КI-091: Притуп Ю.Л., Нестеренко О.I.");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJPanel1(), null);
			jContentPane.add(getJTabbedPane1(), null);
			jContentPane.add(jLabel, null);
			jContentPane.add(getJSplitPane(), null);
			
		}
		return jContentPane;
	}




	

	/**
	 * This method initializes experimentControl	
	 * 	
	 * @return experiment.controls.ExperimentControl	
	 */
	private ExperimentControl getExperimentControl() {
		if (experimentControl == null) {
			experimentControl = new ExperimentControl();
			experimentControl.setBounds(new Rectangle(5, 0, 223, 226));
			experimentControl.setDiagram(getDiagramZavisimost());
			experimentControl.setTextFactors("1 3 9");
			experimentControl.setFactory(getFactoryForRgrModel1());
			//experimentControl.setModelFace(this);
		}
		return experimentControl;
	}

	/**
	 * This method initializes regresAnaliser	
	 * 	
	 * @return experiment.regres.RegresAnaliser	
	 */
	private RegresAnaliser getRegresAnaliser() {
		if (regresAnaliser == null) {
			regresAnaliser = new RegresAnaliser();
			regresAnaliser.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
			regresAnaliser.setBounds(new Rectangle(230, 11, 249, 215));
			regresAnaliser.setDiagram(getDiagramZavisimost());
			regresAnaliser.setExperimentControl(getExperimentControl());
			
			

		}
		return regresAnaliser;
	}

	private FactoryForRgrModel getFactoryForRgrModel1() {
		if (factoryForRgrModel1 == null) {
			factoryForRgrModel1 = new FactoryForRgrModel(this);
		}
		return factoryForRgrModel1;
	}
	
	/**
	 * This method initializes chooseData41	
	 * 	
	 * @return widgets.ChooseData	
	 */
	ChooseData getChooseData41() {
		if (chooseDataGruz == null) {
			chooseDataGruz = new ChooseData();
			chooseDataGruz.setTitle("Кол-во грузовиков");
			chooseDataGruz.setSize(new Dimension(124, 48));
			chooseDataGruz.setText("5");
		}
		return chooseDataGruz;
	}
	
	public void startStat() {
		getDiagram3().clear();
		getDiagram31().clear();
		getJTextArea().setText("");
		getJTextArea1().setText("");
		FactoryForRgrModel factory = new FactoryForRgrModel(Main.this);
		final Dispatcher dispatcher = new Dispatcher();
		final Model model = factory.createModel(dispatcher);
		model.initForStat();
		dispatcher.start();
		getJButtonStat().setEnabled(false);
		// Створюємо потік, що чекає завершення роботи диспетчера
		// а після цього відновлює доступність кнопки "Почати експеримент"
		// та виводить на екран статистичні характеристики черги
		new Thread() {
			public void run() {
				try {
					dispatcher.getThread().join();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				getJButtonStat().setEnabled(true);
				
				model.getHisto().showRelFrec(getDiagram3());
				getJTextArea().setText(model.getHisto().toString());
				getJTextArea().select(0, 0);
				
				model.getHisto1().showRelFrec(getDiagram31());
				getJTextArea1().setText(model.getHisto1().toString());
				getJTextArea1().select(0, 0);
			}
		}.start();

	}
	
}
